$(function(){
        //管道公司获取管道信息
        $('.form-builder').on('change','#pipeline_company',function(){
            $.ajax({
                data:{
                    company_id:$(this).val()
                },
                url:'ajax_get_pipeline',
                method:'post',
                dataType:'json',
                async:false,
                cache:false,
                success: function (res) {
                    if (res.code) {
                        var html = '<div class="form-group col-lg-12 col-md-12 col-sm-12 col-xs-12" id="form_group_pipeline_number">\n' +
                            '<label class="col-xs-12" for="pipeline_number">管道</label>\n' +
                            '<div class="col-xs-12">\n' +
                            '<select class="js-select2 form-control select2-hidden-accessible" id="pipeline_number" name="pipeline_number[]" data-allow-clear="true" data-placeholder="请选择一项或多项" multiple="" tabindex="-1" aria-hidden="true">\n';
                        $(res.data).each(function (i, v) {
                            console.debug(i);
                            html += '<option value="'+ v.id +'">' + v.name + '</option>\n';
                        });
                        html += '</select>' +
                            '<div class="help-block"><span class="text-danger">必填</span></div>\n' +
                            '</div>\n' +
                            '</div>';
                        $("#form_group_pipeline_number").remove();
                        $("#form_group_pipeline_company").after(html);
                        //初始化selete2
                        var $select2 =$("#pipeline_number");
                        var $width=$select2.data('width') || '100%';
                        $select2.select2({
                            width: $width, //设置下拉框的宽度
                            language: "zh-CN"
                        });
                    }



                    // $('.js-select2').each(function () {
                    //
                    //     var $width = $select2.data('width') || '100%';
                    //     $select2.select2({
                    //         width: $width, //设置下拉框的宽度
                    //         language: "zh-CN"
                    //     });
                    // });

                }
            });
        });
        //设备获取管道公司信息
        $('.form-builder').on('change','#equipment_number',function(){
            $.ajax({
                url:'ajax_get_pipecompany',
                data:{
                    equipment_number:$(this).val()
                },
                method:'post',
                async:false,
                cache:false,
                success:function(res){
                    if (res.code) {
                        var html = '<div class="form-group col-lg-12 col-md-12 col-sm-12 col-xs-12" id="form_group_pipeline_company">\n' +
                            '<label class="col-xs-12" for="pipeline_company">管道所属公司</label>\n' +
                            '<div class="col-xs-12">\n' +
                            '<select class="js-select2 form-control select2-hidden-accessible" id="pipeline_company" name="pipeline_company[]" data-allow-clear="true" data-placeholder="请选择一项或多项" multiple="" tabindex="-1" aria-hidden="true">\n';
                        $(res.data).each(function (i, v) {
                            console.debug(i);
                            html += '<option value="'+ v.id +'">' + v.name + '</option>\n';
                        });
                        html += '</select>' +
                            '<div class="help-block"><span class="text-danger">必填</span></div>\n' +
                            '</div>\n' +
                            '</div>';

                        $("#form_group_pipeline_company").remove();
                        $("#form_group_equipment_number").after(html);
                        //初始化selete2
                        var $select2 =$("#pipeline_company");
                        var $width=$select2.data('width') || '100%';
                        $select2.select2({
                            width: $width, //设置下拉框的宽度
                            language: "zh-CN"
                        });
                    }
                }
            });
        });




    });
